package org.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

@WebServlet("/postform")
public class PostFormServlet extends HelloServlet{
    @Override
    /**
     * 处理post请求
     */
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        // 设置响应内容类型
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter out = resp.getWriter();
        String title = "使用 POST 方法读取表单数据";
        String name = req.getParameter("username");
        String pwd = req.getParameter("password");
        out.print(title);
        out.print("<br>接收到的用户姓名为:"+name);
        out.print("<br>接收到的用户密码为:"+pwd);
        out.flush();
        out.close();
    }
}
